package com.xing.controller;

import com.xing.Utils.Result;
import com.xing.dto.LiveAttentionDTO;
import com.xing.dto.LiveAttentionUserDTO;
import com.xing.service.LiveAttentionService;
import com.xing.utils.PageData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户关注粉丝服务")
@RestController
@RequestMapping(value = "attention")
public class LiveAttentionController {

    @Autowired
    private LiveAttentionService liveAttentionService;


    @Operation(summary = "根据id关注用户")
    @GetMapping(value = "attentionById")
    public Result attentionToById(@RequestParam("attentionedId") Long attentionedId) {
        return liveAttentionService.attentionTo(attentionedId);
    }

    @Operation(summary = "根据id取消关注")
    @GetMapping(value = "cancelAttentionById")
    public Result cancelAttentionById(@RequestParam("attentionedId") Long attentionedId) {
        return liveAttentionService.cancelAttention(attentionedId);
    }


    @Operation(summary = "获取当前用户关注列表")
    @GetMapping(value = "getAttentionList")
    public Result getAttentionList() {
        List<LiveAttentionUserDTO> attentionUserList = liveAttentionService.getAttentionList();
        return new Result().ok(attentionUserList);
    }


    @Operation(summary = "获取当前用户粉丝列表")
    @GetMapping(value = "getAttentionedList")
    public Result getAttentionedList() {
        List<LiveAttentionUserDTO> attentionUserList = liveAttentionService.getAttentionedList();
        return new Result().ok(attentionUserList);
    }


    @Operation(summary = "根据id获取用户关注列表")
    @GetMapping(value = "getAttentionListByUserId")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result getAttentionListByUserId(@RequestParam Long userId) {
        List<LiveAttentionUserDTO> attentionUserList = liveAttentionService.getAttentionListByUserId(userId);
        return new Result().ok(attentionUserList);
    }


    @Operation(summary = "获取id当前用户粉丝列表")
    @GetMapping(value = "getAttentionedListByUserId")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result getAttentionedListByUserId(@RequestParam Long userId) {
        List<LiveAttentionUserDTO> attentionUserList = liveAttentionService.getAttentionedListByUserId(userId);
        return new Result().ok(attentionUserList);
    }

    @Operation(summary = "分页查询关注")
    @GetMapping(value = "getAttentionPage")
    public Result getAttentionPage(@RequestParam("page")Integer page,@RequestParam("limit") Integer limit) {
        PageData<LiveAttentionUserDTO> pageData = liveAttentionService.getAttentionPage(page,limit);
        return new Result().ok(pageData);
    }


    @Operation(summary = "分页查询粉丝")
    @GetMapping(value = "getAttentionedPage")
    public Result getAttentionedPage(@RequestParam("page")Integer page,@RequestParam("limit") Integer limit) {
        PageData<LiveAttentionUserDTO> pageData = liveAttentionService.getAttentionedPage(page,limit);
        return new Result().ok(pageData);
    }


}
